"""
Inguma Penetration Testing Toolkit
Copyright (c) 2006, 2007 Joxean Koret, joxeankoret [at] yahoo.es

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""
import os
import sys

STANDARD_USERS = [
	'SYS',
	'SYSTEM',
	'SYSADM',
	'SYSADMIN',
	'SYSMAN',
	'CTXDEMO',
	'CTXSYS',
	'MDSYS',
	'MTSSYS',
	'ODM',
	'OLAPSYS',
	'OLAPDBA',
	'ORASSO',
	'ORASSO_DS',
	'ORASSO_PA',
	'ORASSO_PS',
	'ORASSO_PUBLIC',
	'ORASTAT',
	'ORCLADMIN',
	'ORDCOMMON',
	'DATA_SCHEMA',
	'DBSNMP',
	'BRIO_ADMIN',
	'BRUGERNAVN',
	'BRUKERNAVN',
	'BSC',
	'BUG_REPORTS',
	'CALVIN',
	'CATALOG',
	'CCT',
	'CDEMO82',
	'CDEMOCOR',
	'CDEMORID',
	'CDEMOUCB',
	'CDOUGLAS',
	'CE',
	'CENTRA',
	'CENTRAL',
	'CIDS',
	'CIS',
	'CISINFO',
	'CLARK',
	'CLKANA',
	'CLKRT',
	'CN',
	'COMPANY',
	'COMPIERE',
	'CQSCHEMAUSER',
	'CQUSERDBUSER',
	'CRP',
	'CS',
	'CSC',
	'CSD',
	'CSE',
	'CSF',
	'CSI',
	'CSL',
	'CSMIG',
	'CSP',
	'CSR',
	'CSS',
	'CUA',
	'CUE',
	'CUF',
	'CUG',
	'CUI',
	'CUN',
	'CUP',
	'CUS',
	'CZ',
	'DBI',
	'HR',
	'HRI',
	'HVST',
	'HXC',
	'HXT',
	'IBA',
	'IBE',
	'IBP',
	'IBU',
	'IBY',
	'ICDBOWN',
	'ICX',
	'IDEMO_USER',
	'IEB',
	'IEC',
	'IEM',
	'IEO',
	'IES',
	'IEU',
	'IEX',
	'IFSSYS',
	'IGC',
	'IGF',
	'IGI',
	'IGS',
	'IGW',
	'IMAGEUSER',
	'IMC',
	'IMEDIA',
	'IMT',
	'#INTERNAL',
	'INTERNAL',
	'INV',
	'IPA',
	'IPD',
	'IPLANET',
	'ISC',
	'ITG',
	'JA',
	'JAKE',
	'JE',
	'JG',
	'JILL',
	'JL',
	'JMUSER',
	'JOHN',
	'JONES',
	'JTF',
	'JTM',
	'JTS',
	'JWARD',
	'KWALKER',
	'L2LDEMO',
	'LBACSYS',
	'LIBRARIAN',
	'MANPROD',
	'MARK',
	'MASCARM',
	'MASTER',
	'MDDATA',
	'MDDEMO',
	'MDDEMO_CLERK',
	'MDDEMO_MGR',
	'ME',
	'MFG',
	'MGR',
	'MGWUSER',
	'MIGRATE',
	'MILLER',
	'MMO2',
	'MODTEST',
	'MOREAU',
	'MRP',
	'MSC',
	'MSD',
	'MSO',
	'MSR',
	'MTS_USER',
	'MWA',
	'MXAGENT',
	'NAMES',
	'NEOTIX_SYS',
	'NNEUL',
	'NOM_UTILISATEUR',
	'NOMEUTENTE',
	'NOME_UTILIZADOR',
	'NUME_UTILIZATOR',
	'OAIHUB902',
	'OAS_PUBLIC',
	'OCITEST',
	'OCM_DB_ADMIN',
	'ODM_MTR',
	'ODS',
	'ODS_SERVER',
	'ODSCOMMON',
	'OE',
	'OEM_REPOSITORY',
	'OEMADM',
	'OEMREP',
	'OKB',
	'OKC',
	'OKE',
	'OKI',
	'OKO',
	'OKR',
	'OKS',
	'OKX',
	'OLAPSVR',
	'OMWB_EMULATION',
	'ONT',
	'OO',
	'OPENSPIRIT',
	'OPI',
	'ORACACHE',
	'ORACLE',
	'ORADBA',
	'ORANGE',
	'ORAPROBE',
	'ORAREGSYS',
	'DBVISION',
	'DCM',
	'DDIC',
	'DEMO',
	'DEMO8',
	'DEMO9',
	'DES',
	'DES2K',
	'DEV2000_DEMOS',
	'DIANE',
	'DIP',
	'DISCOVERER_ADMIN',
	'DISCOVERER5',
	'DMSYS',
	'DPF',
	'DSGATEWAY',
	'DSSYS',
	'DTSP',
	'EAA',
	'EAM',
	'EARLYWATCH',
	'EAST',
	'EC',
	'ECX',
	'EJB',
	'EJSADMIN',
	'EMP',
	'ENG',
	'ENI',
	'ESTOREUSER',
	'EVENT',
	'EVM',
	'EXAMPLE',
	'EXFSYS',
	'EXTDEMO',
	'EXTDEMO2',
	'FA',
	'FEM',
	'FII',
	'FINANCE',
	'FINPROD',
	'FLM',
	'FND',
	'FOO',
	'FPT',
	'FRM',
	'FROSTY',
	'FTE',
	'FV',
	'GL',
	'GMA',
	'GMD',
	'GME',
	'GMF',
	'GMI',
	'GML',
	'GMP',
	'GMS',
	'GPFD',
	'GPLD',
	'GR',
	'HADES',
	'HCPARK',
	'HLW',
	'HR',
	'ABM',
	'ADAMS',
	'ADLDEMO',
	'ADMIN',
	'ADMINISTRATOR',
	'AHL',
	'AHM',
	'AK',
	'ALHRO',
	'ALHRW',
	'ALR',
	'AMS',
	'AMV',
	'ANDY',
	'ANONYMOUS',
	'AP',
	'APPLMGR',
	'APPLSYS',
	'APPLSYSPUB',
	'APPLYSYSPUB',
	'APPS',
	'APPS_MRC',
	'APPUSER',
	'AQ',
	'AQDEMO',
	'AQJAVA',
	'AQUSER',
	'AR',
	'ASF',
	'ASG',
	'ASL',
	'ASO',
	'ASP',
	'AST',
	'ATM',
	'AUDIOUSER',
	'AURORA$JIS$UTILITY$',
	'AURORA$ORB$UNAUTHENTICATED',
	'AX',
	'AZ',
	'BC4J',
	'BEN',
	'BIC',
	'BIL',
	'BIM',
	'BIS',
	'BIV',
	'BIX',
	'BLAKE',
	'BLEWIS',
	'BOM',
	'SYSMAN',
	'SYSTEM',
	'TAHITI',
	'TALBOT',
	'TDOS_ICSAP',
	'TEC',
	'TEST',
	'TEST_USER',
	'TESTPILOT',
	'THINSAMPLE',
	'TIBCO',
	'TIP37',
	'TRACESVR',
	'TRAVEL',
	'TSDEV',
	'TSUSER',
	'TURBINE',
	'UDDISYS',
	'ULTIMATE',
	'UM_ADMIN',
	'UM_CLIENT',
	'USER',
	'USER_NAME',
	'USER0',
	'USER1',
	'USER2',
	'USER3',
	'USER4',
	'USER5',
	'USER6',
	'USER7',
	'USER8',
	'USER9',
	'UTILITY',
	'USUARIO',
	'UTLBSTATU',
	'VEA',
	'VEH',
	'VERTEX_LOGIN',
	'VIDEOUSER',
	'VIF_DEVELOPER',
	'VIRUSER',
	'VPD_ADMIN',
	'VRR1',
	'WEBCAL01',
	'WEBDB',
	'WEBREAD',
	'WEBSYS',
	'WEBUSER',
	'WEST',
	'WFADMIN',
	'WH',
	'WIP',
	'WIRELESS',
	'WKADMIN',
	'WKPROXY',
	'WKSYS',
	'WKPROXY',
	'WKSYS',
	'WKUSER',
	'WK_SYS',
	'WK_TEST',
	'WK_PROXY',
	'WMS',
	'WMSYS',
	'WOB',
	'WPS',
	'WSH',
	'WSM',
	'WWW',
	'WWWUSER',
	'XADEMO',
	'XDB',
	'XDP',
	'XLA',
	'XNC',
	'XNI',
	'XNM',
	'XNP',
	'XNS',
	'XPRT',
	'XTR',
	'MDDEMO_MGR',
	'SYSTEM',
	'SYS',
	'ORDPLUGINS',
	'ORDSYS',
	'OSE$HTTP$ADMIN',
	'OSM',
	'OSP22',
	'OSSAQ_HOST',
	'OSSAQ_PUB',
	'OSSAQ_SUB',
	'OTA',
	'OUTLN',
	'OWA',
	'OWA_PUBLIC',
	'OWF_MGR',
	'OWNER',
	'OZF',
	'OZP',
	'OZS',
	'PA',
	'PANAMA',
	'PATROL',
	'PAUL',
	'PERFSTAT',
	'PERSTAT',
	'PJM',
	'PLANNING',
	'PLEX',
	'PLSQL',
	'PM',
	'PMI',
	'PN',
	'PO',
	'PO7',
	'PO8',
	'POA',
	'POM',
	'PORTAL',
	'PORTAL_APP',
	'PORTAL_DEMO',
	'PORTAL_PUBLIC',
	'PORTAL_SSO_PS',
	'PORTAL30',
	'PORTAL30_ADMIN',
	'PORTAL30_DEMO',
	'PORTAL30_PS',
	'PORTAL30_PUBLIC',
	'PORTAL30_SSO',
	'PORTAL30_SSO_ADMIN',
	'PORTAL30_SSO_PS',
	'PORTAL30_SSO_PUBLIC',
	'POS',
	'POWERCARTUSER',
	'PRIMARY',
	'PSA',
	'PSB',
	'PSP',
	'PUBSUB',
	'PUBSUB1',
	'PV',
	'QA',
	'QDBA',
	'QP',
	'QS',
	'QS_ADM',
	'QS_CB',
	'QS_CBADM',
	'QS_CS',
	'QS_ES',
	'QS_OS',
	'QS_WS',
	'RE',
	'REP_MANAGER',
	'REP_OWNER',
	'REP_USER',
	'REPADMIN',
	'REPORTS_USER',
	'REPORTS',
	'RG',
	'RHX',
	'RLA',
	'RLM',
	'RMAIL',
	'RMAN',
	'RRS',
	'SAMPLE',
	'SAP',
	'SAPR3',
	'SCOTT',
	'SDOS_ICSAP',
	'SECDEMO',
	'SERVICECONSUMER1',
	'SH',
	'SITEMINDER',
	'SI_INFORMTN_SCHEMA',
	'SLIDE',
	'SPIERSON',
	'SSP',
	'STARTER',
	'STRAT_USER',
	'SWPRO',
	'SWUSER',
	'SYMPA'
]

STANDARD_SIDS = [
	'ORCL',
	'ORCL11',
	'ORCL10',
	'ORCL92',
	'ORCL9',
	'ORCL8I',
	'ORCL8',
	'XE',
	'ASDB',
	'IASDB',
	'OEMREP',
	'SA0',
	'SA1',
	'SA2',
	'SA3',
	'SA4',
	'SA5',
	'SA6',
	'SA7',
	'SA8',
	'SA9',
	'SAA',
	'SAB',
	'SAC',
	'SAD',
	'SAE',
	'SAF',
	'SAG',
	'SAH',
	'SAI',
	'SAJ',
	'SAK',
	'SAL',
	'SAM',
	'SAN',
	'SAO',
	'SAP',
	'SAQ',
	'SAR',
	'SAS',
	'SAT',
	'SAU',
	'SAV',
	'SAW',
	'SAX',
	'SAY',
	'SAZ',
	'IXOS',
	'CTM4_0',
	'CTM4_1',
	'CTM4_6',
	'CTM4_6',
	'ARIS',
	'MSAM',
	'ADV1',
	'ADVCPROD',
	'ASDB0',
	'ASDB1',
	'ASDB2',
	'ASDB3',
	'ASDB4',
	'ASDB5',
	'ASDB6',
	'ASDB7',
	'ASDB8',
	'ASDB9',
	'ASG817',
	'ASG817P',
	'ASG817T',
	'ATRPROD',
	'ATRTEST',
	'BLA',
	'BUDGET',
	'C630',
	'D',
	'D10',
	'D8',
	'D9',
	'DB',
	'DB01',
	'DB02',
	'DB03',
	'DB1',
	'DB2',
	'DB2EDU',
	'DB2PROD',
	'DB2TEST',
	'DB3',
	'DBA',
	'DBA1',
	'DBA2',
	'DBA3',
	'DBA4',
	'DBA5',
	'DBA6',
	'DBA7',
	'DBA8',
	'DBA9',
	'DBX',
	'DEMO',
	'DEV',
	'DEV0',
	'DEV1',
	'DEV2',
	'DEV3',
	'DEV4',
	'DEV5',
	'DEV6',
	'DEV7',
	'DEV8',
	'DEV9',
	'DEVEL',
	'DIA1',
	'DIA2',
	'DIS',
	'DWH',
	'DWHPROD',
	'DWHTEST',
	'DWRHS',
	'ELCARO',
	'EMRS2',
	'EOF',
	'ESOR',
	'FINDEC',
	'FINPROD',
	'FNDFS_HR1',
	'FNDFS_HR2',
	'FPRD',
	'GR01',
	'GR02',
	'GR03',
	'HR',
	'HR0',
	'HR1',
	'HR2',
	'HR3',
	'HR4',
	'HR5',
	'HR6',
	'HR7',
	'HR8',
	'HR9',
	'HRDMO',
	'INCD',
	'ISD01',
	'ISD06',
	'ISP01',
	'ITS',
	'KRAUS',
	'KRONOS',
	'LDAP',
	'LINUX101',
	'LINUX1011',
	'LINUX1012',
	'LINUX1013',
	'LINUX1014',
	'LINUX102',
	'LINUX1021',
	'LINUX817',
	'LINUX8171',
	'LINUX8172',
	'LINUX8173',
	'LINUX8174',
	'LINUX901',
	'LINUX902',
	'LINUX9021',
	'LINUX9022',
	'LINUX9023',
	'LINUX9024',
	'LINUX9025',
	'LINUX9026',
	'LINUX9027',
	'LUN',
	'MDTEST',
	'MYDB',
	'NEDB',
	'NORTHWIND',
	'ODB',
	'OGDP',
	'OID',
	'OJS',
	'OMS',
	'ORA1',
	'ORA10',
	'ORA101',
	'ORA10101',
	'ORA10101P',
	'ORA10101T',
	'ORA10102',
	'ORA10102P',
	'ORA10102T',
	'ORA10103',
	'ORA10103P',
	'ORA10103T',
	'ORA10104',
	'ORA10104P',
	'ORA10104T',
	'ORA10105',
	'ORA10105P',
	'ORA10105T',
	'ORA1011',
	'ORA1011P',
	'ORA1011T',
	'ORA1012',
	'ORA1012P',
	'ORA1012T',
	'ORA1013',
	'ORA1013P',
	'ORA1013T',
	'ORA1014',
	'ORA1014P',
	'ORA1014T',
	'ORA1015',
	'ORA1015P',
	'ORA1015T',
	'ORA1021',
	'ORA1021P',
	'ORA1021T',
	'ORA1022',
	'ORA1022P',
	'ORA1022T',
	'ORA2',
	'ORA8',
	'ORA805',
	'ORA806',
	'ORA815',
	'ORA816',
	'ORA817',
	'ORA8170',
	'ORA8170P',
	'ORA8170T',
	'ORA8171',
	'ORA8171P',
	'ORA8171T',
	'ORA8172',
	'ORA8172P',
	'ORA8172T',
	'ORA8173',
	'ORA8173P',
	'ORA8173T',
	'ORA8174',
	'ORA8174P',
	'ORA8174T',
	'ORA8_SC',
	'ORA910',
	'ORA920',
	'ORA9201',
	'ORA9201P',
	'ORA9201T',
	'ORA9202',
	'ORA9202P',
	'ORA9202T',
	'ORA9203',
	'ORA9203P',
	'ORA9203T',
	'ORA9204',
	'ORA9204P',
	'ORA9204T',
	'ORA9205',
	'ORA9205P',
	'ORA9205T',
	'ORA9206',
	'ORA9206P',
	'ORA9206T',
	'ORA9207',
	'ORA9207P',
	'ORA9207T',
	'ORACL',
	'ORACLE',
	'ORADB',
	'ORADB1',
	'ORADB2',
	'ORADB3',
	'ORALIN',
	'ORCL0',
	'ORCL1',
	'ORCL10',
	'ORCL2',
	'ORCL3',
	'ORCL4',
	'ORCL5',
	'ORCL6',
	'ORCL7',
	'ORCL8',
	'ORCL9',
	'ORCLA',
	'ORCLB',
	'ORCLC',
	'ORCLD',
	'ORCLE',
	'ORCLF',
	'ORCLG',
	'ORCLH',
	'ORCLI',
	'ORCLJ',
	'ORCLK',
	'ORCLL',
	'ORCLM',
	'ORCLN',
	'ORCLO',
	'ORCLP',
	'ORCLP0',
	'ORCLP1',
	'ORCLP2',
	'ORCLP3',
	'ORCLP4',
	'ORCLP5',
	'ORCLP6',
	'ORCLP7',
	'ORCLP8',
	'ORCLP9',
	'ORCLQ',
	'ORCLR',
	'ORCLS',
	'ORCLSOL',
	'ORCLT',
	'ORCLU',
	'ORCLV',
	'ORCLW',
	'ORCLX',
	'ORCLY',
	'ORCLZ',
	'ORIONDB',
	'ORTD',
	'P',
	'P10',
	'P10G',
	'P8',
	'P8I',
	'P9',
	'P9I',
	'PD1',
	'PINDB',
	'PORA10101',
	'PORA10102',
	'PORA10103',
	'PORA10104',
	'PORA10105',
	'PORA1011',
	'PORA1012',
	'PORA1013',
	'PORA1014',
	'PORA1015',
	'PORA1021',
	'PORA1022',
	'PORA8170',
	'PORA8171',
	'PORA8172',
	'PORA8173',
	'PORA8174',
	'PORA9201',
	'PORA9202',
	'PORA9203',
	'PORA9204',
	'PORA9205',
	'PORA9206',
	'PORA9207',
	'PRD',
	'PRITXI',
	'PROD',
	'PROD0',
	'PROD1',
	'PROD10G',
	'PROD2',
	'PROD3',
	'PROD4',
	'PROD5',
	'PROD6',
	'PROD7',
	'PROD8',
	'PROD8I',
	'PROD9',
	'PROD920',
	'PROD9I',
	'PROG10',
	'RAB1',
	'RAC',
	'RAC1',
	'RAC2',
	'RAC3',
	'RAC4',
	'RECV',
	'REP',
	'REP0',
	'REP1',
	'REP2',
	'REP3',
	'REP4',
	'REP5',
	'REP6',
	'REP7',
	'REP8',
	'REP9',
	'REPO',
	'REPO0',
	'REPO1',
	'REPO2',
	'REPO3',
	'REPO4',
	'REPO5',
	'REPO6',
	'REPO7',
	'REPO8',
	'REPO9',
	'REPOS',
	'REPOS0',
	'REPOS1',
	'REPOS2',
	'REPOS3',
	'REPOS4',
	'REPOS5',
	'REPOS6',
	'REPOS7',
	'REPOS8',
	'REPOS9',
	'RIPPROD',
	'RITCTL',
	'RITDEV',
	'RITPROD',
	'RITQA',
	'RITTRN',
	'RITTST',
	'SALES',
	'SAMPLE',
	'SANIPSP',
	'SAP',
	'SAP0',
	'SAP1',
	'SAP2',
	'SAP3',
	'SAP4',
	'SAP5',
	'SAP6',
	'SAP7',
	'SAP8',
	'SAP9',
	'SAPHR',
	'SGNT',
	'SID0',
	'SID1',
	'SID2',
	'SID3',
	'SID4',
	'SID5',
	'SID6',
	'SID7',
	'SID8',
	'SID9',
	'STAG1',
	'STAG2',
	'T1',
	'T10',
	'T101',
	'T102',
	'T2',
	'T3',
	'T4',
	'T7',
	'T71',
	'T72',
	'T73',
	'T8',
	'T80',
	'T81',
	'T82',
	'T9',
	'T91',
	'T92',
	'TEST',
	'TEST10G',
	'THUMPER',
	'TRC28',
	'TRIUMF',
	'TSH1',
	'TST',
	'TST0',
	'TST1',
	'TST2',
	'TST3',
	'TST4',
	'TST5',
	'TST6',
	'TST7',
	'TST8',
	'TST9',
	'TYCP',
	'UNIX101',
	'UNIX1011',
	'UNIX1012',
	'UNIX1013',
	'UNIX1014',
	'UNIX102',
	'UNIX1021',
	'UNIX817',
	'UNIX8171',
	'UNIX8172',
	'UNIX8173',
	'UNIX8174',
	'UNIX901',
	'UNIX902',
	'UNIX9021',
	'UNIX9022',
	'UNIX9023',
	'UNIX9024',
	'UNIX9025',
	'UNIX9026',
	'UNIX9027',
	'VENOM',
	'VENU',
	'VISTA',
	'W101',
	'W1011',
	'W1012',
	'W1013',
	'W1014',
	'W102',
	'W1021',
	'W817',
	'W8171',
	'W8172',
	'W8173',
	'W8174',
	'W901',
	'W902',
	'W9021',
	'W9022',
	'W9023',
	'W9024',
	'W9025',
	'W9026',
	'W9027',
	'WG73 ',
	'WIN101',
	'WIN1011',
	'WIN1012',
	'WIN1013',
	'WIN1014',
	'WIN102',
	'WIN1021',
	'WIN817',
	'WIN8171',
	'WIN8172',
	'WIN8173',
	'WIN8174',
	'WIN901',
	'WIN902',
	'WIN9021',
	'WIN9022',
	'WIN9023',
	'WIN9024',
	'WIN9025',
	'WIN9026',
	'WIN9027',
	'WINDOWS101',
	'WINDOWS1011',
	'WINDOWS1012',
	'WINDOWS1013',
	'WINDOWS1014',
	'WINDOWS102',
	'WINDOWS1021',
	'WINDOWS817',
	'WINDOWS8171',
	'WINDOWS8172',
	'WINDOWS8173',
	'WINDOWS8174',
	'WINDOWS901',
	'WINDOWS902',
	'WINDOWS9021',
	'WINDOWS9022',
	'WINDOWS9023',
	'WINDOWS9024',
	'WINDOWS9025',
	'WINDOWS9026',
	'WINDOWS9027',
	'XEXDB',
	'XE_XPT'
]

def getPayload(dict, index = None):
    """
    NOTE: Should be changed in order to make it working with the QT gui
    """
    path = dict["base_path"]
    if path != "":
        path += os.sep

    path += "payloads" + os.sep + "oracle"
    sys.path.append(path)

    print "Select payload"
    print "--------------"
    print

    i = 0
    modList = {}

    for x in os.listdir(path):
        i += 1

        if x.endswith(".py") and x != "__init__.py":
            data = x[:x.find(".py")]
            modList[i] = data
            print i, data

    print

    try:
        res = raw_input("Payload: ")

        bSelected = False
        for x in modList:
            if str(x) == str(res):
                res = modList[x]
                bSelected = True
            elif modList[x].find(res) > -1:
                res = modList[x]
                bSelected = True

        if not bSelected:
            print "Error. Invalid payload"
            raise Exception("Invalid payload")
        else:
            print "Selected payload '%s'" % res
    except:
        raise Exception("Bad payload")

    exec("import " + res)
    return eval(res + ".CPayload()")

